package com.ibm.commerce.order.facade.server.commands;

import java.math.BigDecimal;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

import javax.xml.datatype.DatatypeConfigurationException;

import com.efacil.commerce.order.helpers.NotaFiscalEfacilHelper;
import com.ibm.commerce.foundation.common.datatypes.CommerceFoundationFactory;
import com.ibm.commerce.foundation.common.datatypes.MonetaryAmountType;
import com.ibm.commerce.foundation.common.datatypes.OrderChargesType;
import com.ibm.commerce.foundation.common.datatypes.OrderIdentifierType;
import com.ibm.commerce.foundation.common.datatypes.PersonIdentifierType;
import com.ibm.commerce.foundation.common.datatypes.StoreIdentifierType;
import com.ibm.commerce.foundation.common.util.sdo.SDODataTypeHelper;
import com.ibm.commerce.order.facade.datatypes.ChannelIdentiferType;
import com.ibm.commerce.order.facade.datatypes.ChannelType;
import com.ibm.commerce.order.facade.datatypes.OrderFactory;
import com.ibm.commerce.order.facade.datatypes.OrderPaymentInfoType;
import com.ibm.commerce.order.facade.datatypes.OrderStatusType;
import com.ibm.commerce.order.facade.datatypes.OrderType;
import com.ibm.commerce.order.facade.datatypes.PaymentInstructionType;
import com.ibm.commerce.order.facade.datatypes.ShowOrderDataAreaType;
import com.ibm.commerce.order.facade.datatypes.ShowOrderType;
import com.ibm.commerce.order.facade.datatypes.impl.OrderTypeImpl;
import com.ibm.websphere.command.CommandException;

public class ComposeOrderDetailsCmdImpl2 extends ComposeOrderDetailsCmdImpl{
	
	/*
	  
	  
	 INSERT INTO COMMERCE.CMDREG (STOREENT_ID, INTERFACENAME, DESCRIPTION, CLASSNAME, PROPERTIES, LASTUPDATE, TARGET, OPTCOUNTER)
	VALUES (0, 'com.ibm.commerce.order.facade.server.commands.ComposeOrderCmd+IBM_SummaryXX', NULL, 'com.ibm.commerce.order.facade.server.commands.ComposeOrderDetailsCmdImpl2', NULL, NULL, 'Local', NULL);

	  
	<wcf:getData type="com.ibm.commerce.order.facade.datatypes.OrderType[]"   scope="request" var="allOrdersInThisCategory" varShowVerb="ShowVerbAllOrdersInThisCategory" expressionBuilder="findByOrderStatus" maxItems="${max}" recordSetStartNumber="${start}" recordSetReferenceId="orderstatus">
			<wcf:param name="status" value="${arrayStatusString}" />
			<wcf:param name="accessProfile" value="IBM_SummaryXX" />
	</wcf:getData>
	 
	 * */
	
	
	
	
	@Override
	  public void execute(){
	
		System.out.println("OK");
		  try {
			super.execute();
			NotaFiscalEfacilHelper nfHelper = new NotaFiscalEfacilHelper();
			try {
				nfHelper.getxml();
				
			} catch (DatatypeConfigurationException e) {
				
				e.printStackTrace();
			}
			
		   /*
		         ShowOrderType sot = this.getShowOrder();
		         ShowOrderDataAreaType sodat = sot.getDataArea();
		         List l = sodat.getOrder();
		         
		        //Creo el orderType...
		        
		         OrderType o = OrderFactory.eINSTANCE.createOrderType();
		         l.add(o);
		   
		         //OrderItdentifier  
		         OrderIdentifierType  orderIdentifier = CommerceFoundationFactory.eINSTANCE.createOrderIdentifierType();
		   			      orderIdentifier.setUniqueID("32387");
		   			      orderIdentifier.setCustomerOrderNumber("");
		   			      orderIdentifier.setExternalOrderID(null);
		     
		   	o.setOrderIdentifier(orderIdentifier);
		   
		   	
		   	//OrderCharges
		   		OrderChargesType orderCharges = CommerceFoundationFactory.eINSTANCE.createOrderChargesType();; 
		   			MonetaryAmountType total = CommerceFoundationFactory.eINSTANCE.createMonetaryAmountType();
		   			 total.setCurrency("USD");
		   			 total.setValue(new BigDecimal(15));
		   			
		   		orderCharges.setGrandTotal(total);
		   	//seteo el order Charge	
		         o.setOrderAmount(orderCharges);
		         
		        //OrderStatus
		         OrderStatusType orderStatus =  OrderFactory.eINSTANCE.createOrderStatusType();
		         orderStatus.setStatus("M");
		         o.setOrderStatus(orderStatus);
		     
		         
		         //OrderTypeCode
		         o.setOrderTypeCode("ORD");
		         
		         o.setOrderDescription("SERVICIO");
		         
		         o.setComments(null);
		         
		         //OrderPaymentInfo --- Revisar este compose... falta complete momentaneamente con null
		         OrderPaymentInfoType orderPay = OrderFactory.eINSTANCE.createOrderPaymentInfoType();
		         List result = new ArrayList(1);
		         	PaymentInstructionType paymentInstType = OrderFactory.eINSTANCE.createPaymentInstructionType();
		         	result.add(paymentInstType);
		         			
		         			paymentInstType.setPaymentMethod(null); //completar
		         			paymentInstType.setUniqueID("50001");
		   	      			MonetaryAmountType payAmount = CommerceFoundationFactory.eINSTANCE.createMonetaryAmountType();
		   		      			payAmount.setCurrency("USD");
		   		      			payAmount.setValue(new BigDecimal(15));
		         			paymentInstType.setAmount(payAmount);
		         			
		         orderPay.getPaymentInstruction().addAll(result);
		         o.setOrderPaymentInfo(orderPay);  
		       
		         StoreIdentifierType stoerIdent = CommerceFoundationFactory.eINSTANCE.createStoreIdentifierType();
		         stoerIdent.setUniqueID("12251");
		         o.setStoreIdentifier(stoerIdent);
		       
		         ChannelType channel = OrderFactory.eINSTANCE.createChannelType();
		         ChannelIdentiferType channelIdent = OrderFactory.eINSTANCE.createChannelIdentiferType();
		         channel.setChannelIdentifer(channelIdent);
		         channelIdent.setUniqueID("10001");
		       
		         o.setBuyerPONumber(null);
		       
		         o.setShipAsComplete(true);
		       
		         Date date = new Date(0);
		         o.setLastUpdateDate(SDODataTypeHelper.formatXMLDateTime(date));
		       
		         o.setPlacedDate(date);
		       
		         PersonIdentifierType personIdentifier =CommerceFoundationFactory.eINSTANCE.createPersonIdentifierType();
		         	personIdentifier.setUniqueID("22502");
		         	personIdentifier.setDistinguishedName(null);
		         
		         	o.setBuyerIdentifier(personIdentifier);
		  	*/
		} catch (CommandException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	  }

}
